package com.qf.zhijia.controller;

import com.qf.zhijia.pojo.Item;
import com.qf.zhijia.pojo.Orders;
import com.qf.zhijia.service.ItemService;
import com.qf.zhijia.vo.TableVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author Canaan
 * @version V1.0
 * @data 2020/09/05
 **/
@RestController
@RequestMapping("")
public class ItemController {
    @Autowired
    private ItemService itemService;

    @GetMapping("show")
    public List<Item> show(Integer state, HttpSession session){
        String phone = (String) session.getAttribute("phone");
        List<Item> list = itemService.findAll(state,phone);
        return list;
    }

    @PutMapping("/state")
    public TableVo<Item> updateItem(Item item){
        Integer i = itemService.update(item);
        if (i > 0 ){
            return new TableVo<>(i,"更新状态成功");
        }
        return new TableVo<>(i,"更新状态成功");
    }

}
